home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr44 / modex32w.zip / SC2SC.ASM < prev    next >
Assembly Source File  |  1995-02-21  |  8KB  |  172 lines

  1.         .386p
  2.         locals
  3.         include w.inc
  4.  
  5. ; Mode X (320x240, 256 colors) display memory to display memory copy
  6. ; routine. Left edge of source rectangle modulo 4 must equal left edge
  7. ; of destination rectangle modulo 4. Works on all VGAs. Uses approach
  8. ; of reading 4 pixels at a time from the source into the latches, then
  9. ; writing the latches to the destination. Copies up to but not
  10. ; including the column at SourceEndX and the row at SourceEndY. No
  11. ; clipping is performed. Results are not guaranteed if the source and
  12. ; destination overlap. C near-callable as:
  13. ;    void CopyScreenToScreenX(int SourceStartX, int SourceStartY,
  14. ;       int SourceEndX, int SourceEndY, int DestStartX,
  15. ;       int DestStartY, unsigned int SourcePageBase,
  16. ;       unsigned int DestPageBase, int SourceBitmapWidth,
  17. ;       int DestBitmapWidth);
  18.  
  19. SC_INDEX equ    03c4h   ;Sequence Controller Index register port
  20. MAP_MASK equ    02h     ;index in SC of Map Mask register
  21. GC_INDEX equ    03ceh   ;Graphics Controller Index register port
  22. BIT_MASK equ    08h     ;index in GC of Bit Mask register
  23.  
  24. parms   struc
  25.         dd      2 dup (?) ;pushed BP and return address
  26. SourceStartX dd ?       ;X coordinate of upper left corner of source
  27. SourceStartY dd ?       ;Y coordinate of upper left corner of source
  28. SourceEndX   dd ?       ;X coordinate of lower right corner of source
  29.                         ; (the row at SourceEndX is not copied)
  30. SourceEndY   dd ?       ;Y coordinate of lower right corner of source
  31.                         ; (the column at SourceEndY is not copied)
  32. DestStartX   dd ?       ;X coordinate of upper left corner of dest
  33. DestStartY   dd ?       ;Y coordinate of upper left corner of dest
  34. SourcePageBase dd ?     ;base offset in display memory of page in
  35.                         ; which source resides
  36. DestPageBase dd ?       ;base offset in display memory of page in
  37.                         ; which dest resides
  38. SourceBitmapWidth dd ?  ;# of pixels across source bitmap
  39.                         ; (must be a multiple of 4)
  40. DestBitmapWidth   dd ?  ;# of pixels across dest bitmap
  41.                         ; (must be a multiple of 4)
  42. parms   ends
  43.  
  44. SourceNextScanOffset equ -4   ;local storage for distance from end of
  45.                               ; one source scan line to start of next
  46. DestNextScanOffset equ -8    ;local storage for distance from end of
  47.                               ; one dest scan line to start of next
  48. RectAddrWidth equ -12   ;local storage for address width of rectangle
  49. Height   equ     -16    ;local storage for height of rectangle
  50. STACK_FRAME_SIZE equ 16
  51.  
  52.         @dseg
  53.  
  54.         extrn SCREEN_SEG:dword
  55.         extrn   LeftClipPlaneMask:byte
  56.         extrn   RightClipPlaneMask:byte
  57.  
  58.         ends
  59.         @cseg
  60.  
  61.         public  _CopyScreenToScreenX
  62. _CopyScreenToScreenX proc    near
  63.         push    ebp      ;preserve caller's stack frame
  64.         mov     ebp,esp  ;point to local stack frame
  65.         sub     esp,STACK_FRAME_SIZE ;allocate space for local vars
  66.         push    esi      ;preserve caller's register variables
  67.         push    edi
  68.         push    ebx
  69.  
  70.         cld
  71.         mov     dx,GC_INDEX     ;set the bit mask to select all bits
  72.         mov     ax,00000h+BIT_MASK ; from the latches and none from
  73.         out     dx,ax           ; the CPU, so that we can write the
  74.                                 ; latch contents directly to memory
  75.         mov     eax,[ebp+DestBitmapWidth]
  76.         shr     eax,2            ;convert to width in addresses
  77.         mul     [ebp+DestStartY] ;top dest rect scan line
  78.         mov     edi, [ebp+DestStartX]
  79.         shr     edi,2    ;X/4 = offset of first dest rect pixel in scan line
  80.         add     edi,eax   ;offset of first dest rect pixel in page
  81.         add     edi,[ebp+DestPageBase] ;offset of first dest rect pixel
  82.                         ; in display memory
  83.         mov     eax,[ebp+SourceBitmapWidth]
  84.         shr     eax,2            ;convert to width in addresses
  85.         mul     [ebp+SourceStartY] ;top source rect scan line
  86.         mov     esi, [ebp+SourceStartX]
  87.         mov     ebx,esi
  88.         shr     esi,2    ;X/4 = offset of first source rect pixel in scan line
  89.         add     esi,eax   ;offset of first source rect pixel in page
  90.         add     esi,[ebp+SourcePageBase] ;offset of first source rect
  91.                         ; pixel in display memory
  92.         and     bx,0003h                 ;look up left edge plane mask
  93.         mov     ah,LeftClipPlaneMask[bx] ; to clip
  94.         mov     ebx,[ebp+SourceEndX]
  95.         and     bx,0003h                  ;look up right edge plane
  96.         mov     al,RightClipPlaneMask[bx] ; mask to clip
  97.         mov     bx,ax                   ;put the masks in BX
  98.         
  99.         mov     ecx,[ebp+SourceEndX]   ;calculate # of addresses across
  100.         mov     eax,[ebp+SourceStartX] ; rect
  101.         cmp     ecx,eax
  102.         jle     CopyDone        ;skip if 0 or negative width
  103.         dec     ecx
  104.         and     eax,not 011b
  105.         sub     ecx,eax
  106.         shr     ecx,2    ;# of addresses across rectangle to copy - 1
  107.         jnz     MasksSet ;there's more than one address to draw
  108.         and     bh,bl   ;there's only one address, so combine the left
  109.                         ; and right edge clip masks
  110. MasksSet:
  111.         mov     eax,[ebp+SourceEndY]
  112.         sub     eax,[ebp+SourceStartY]  ;AX = height of rectangle
  113.         jle     CopyDone        ;skip if 0 or negative height
  114.         mov     [ebp+Height],eax
  115.         mov     eax,[ebp+DestBitmapWidth]
  116.         shr     eax,2            ;convert to width in addresses
  117.         sub     eax,ecx   ;distance from end of one dest scan line to
  118.         dec     eax      ; start of next
  119.         mov     [ebp+DestNextScanOffset],eax
  120.         mov     eax,[ebp+SourceBitmapWidth]
  121.         shr     eax,2            ;convert to width in addresses
  122.         sub     eax,ecx   ;distance from end of one source scan line to
  123.         dec     eax      ; start of next
  124.         mov     [ebp+SourceNextScanOffset],eax
  125.         mov     [ebp+RectAddrWidth],ecx ;remember width in addresses - 1
  126.  
  127.         mov     dx,SC_INDEX
  128.         mov     al,MAP_MASK
  129.         out     dx,al           ;point SC Index reg to Map Mask
  130.         inc     dx              ;point to SC Data reg
  131.  
  132.         mov     eax, [SCREEN_SEG]
  133.         add     edi, eax
  134.         add     esi, eax
  135. CopyRowsLoop:
  136.         mov     ecx,[ebp+RectAddrWidth] ;width across - 1
  137.         mov     al,bh   ;put left-edge clip mask in AL
  138.         out     dx,al   ;set the left-edge plane (clip) mask
  139.         movsb           ;copy the left edge (pixels go through
  140.                         ; latches)
  141.         dec     ecx      ;count off left edge address
  142.         js      CopyLoopBottom ;that's the only address
  143.         jz      DoRightEdge ;there are only two addresses
  144.         mov     al,00fh ;middle addresses are drawn 4 pixels at a pop
  145.         out     dx,al   ;set the middle pixel mask to no clip
  146.         rep     movsb   ;draw the middle addresses four pixels apiece
  147.                         ; (pixels copied through latches)
  148. DoRightEdge:
  149.         mov     al,bl   ;put right-edge clip mask in AL
  150.         out     dx,al   ;set the right-edge plane (clip) mask
  151.         movsb           ;draw the right edge (pixels copied through
  152.                         ; latches)
  153. CopyLoopBottom:
  154.         add     esi,[ebp+SourceNextScanOffset] ;point to the start of
  155.         add     edi,[ebp+DestNextScanOffset]  ; next source & dest lines
  156.         dec     dword ptr [ebp+Height] ;count down scan lines
  157.         jnz     CopyRowsLoop
  158. CopyDone:
  159.         mov     dx,GC_INDEX+1 ;restore the bit mask to its default,
  160.         mov     al,0ffh         ; which selects all bits from the CPU
  161.         out     dx,al           ; and none from the latches (the GC
  162.                                 ; Index still points to Bit Mask)
  163.         pop     ebx
  164.         pop     edi      ;restore caller's register variables
  165.         pop     esi
  166.         mov     esp,ebp  ;discard storage for local variables
  167.         pop     ebp      ;restore caller's stack frame
  168.         ret
  169. _CopyScreenToScreenX endp
  170.         ends
  171.         end
  172.